package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;
import com.corona.game.util.TextureCache;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;

/* compiled from: Menu.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/DrawAttacksMenu.class */
class DrawAttacksMenu extends Action {
    public Action.Layer layer;
    public static int curr = 0;
    Sprite arrow;
    Sprite arrowWhite;
    Sprite textBox;
    Map<Integer, Vector2> coords;
    Vector2 newPos;
    Sprite helperSprite;
    ArrayList<ArrayList<Sprite>> spritesToDraw;
    int cursorDelay;
    String attackLearning;
    Vector2 offset;
    Pokemon pokemon;
    boolean isSorting;
    int sortingIndex;

    public DrawAttacksMenu(Action nextAction) {
        this(null, Game.staticGame.player.currPokemon, nextAction);
    }

    public DrawAttacksMenu(String attackLearning, Pokemon pokemon, Action nextAction) {
        super(new Object[0]);
        this.layer = Action.Layer.gui_103;
        this.coords = new HashMap();
        this.spritesToDraw = new ArrayList<>();
        this.attackLearning = null;
        this.offset = new Vector2(0.0f, 0.0f);
        this.isSorting = false;
        this.sortingIndex = -1;
        this.attackLearning = attackLearning;
        this.pokemon = pokemon;
        if (this.attackLearning != null) {
            this.offset.add(0.0f, 48.0f);
        }
        this.nextAction = nextAction;
        this.cursorDelay = 0;
        this.arrow = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right1.png")), 0, 0, 5, 7);
        this.arrowWhite = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right_white.png")), 0, 0, 5, 7);
        this.textBox = new Sprite(TextureCache.get(Gdx.files.internal("menu/attack_screen1.png")), 0, 0, 160, 144);
        this.textBox.setPosition(this.offset.x, this.offset.y);
        this.coords.put(0, new Vector2(41.0f, 32.0f));
        this.coords.put(1, new Vector2(41.0f, 24.0f));
        this.coords.put(2, new Vector2(41.0f, 16.0f));
        this.coords.put(3, new Vector2(41.0f, 8.0f));
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        this.newPos = this.coords.get(Integer.valueOf(curr));
        this.arrow.setPosition(this.newPos.x, this.newPos.y);
        this.spritesToDraw.clear();
        String[] strArr = this.pokemon.attacks;
        for (String attack : strArr) {
            if (attack == null) {
                attack = "-";
            }
            char[] textArray = attack.toUpperCase(Locale.ROOT).toCharArray();
            int i = 0;
            int j = 0;
            ArrayList<Sprite> word = new ArrayList<>();
            for (char letter : textArray) {
                Sprite letterSprite = Game.staticGame.textDict.get(Character.valueOf(letter));
                if (letterSprite == null) {
                    letterSprite = Game.staticGame.textDict.get(null);
                }
                Sprite currSprite = new Sprite(letterSprite);
                currSprite.setPosition((float) (((10 + (8 * i)) + 2) - 4), (((this.offset.y + 26.0f) - ((float) (16 * j))) + 2.0f) - 4.0f);
                word.add(currSprite);
                if (i >= 17) {
                    i = 0;
                    j++;
                } else {
                    i++;
                }
            }
            this.spritesToDraw.add(word);
        }
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "gui";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        Vector2 arrowPos;
        if (InputProcessor.upJustPressed) {
            if (curr != 0) {
                curr--;
                this.newPos = this.coords.get(Integer.valueOf(curr));
            }
        } else if (InputProcessor.downJustPressed && curr + 1 < this.pokemon.attacks.length && this.pokemon.attacks[curr + 1] != null) {
            curr++;
            this.newPos = this.coords.get(Integer.valueOf(curr));
        }
        if (!InputProcessor.aJustPressed) {
            if (InputProcessor.bJustPressed) {
                if (this.attackLearning != null) {
                    game.actionStack.remove(this);
                    game.insertAction(new DisplayText.Clear(game, new WaitFrames(game, 3, new DisplayText(game, "Give up on learning " + this.attackLearning.toUpperCase(Locale.ROOT) + "?", (String) null, true, true, (Action) new DrawYesNoMenu(null, new DisplayText.Clear(game, new WaitFrames(game, 3, new DisplayText(game, this.pokemon.nickname.toUpperCase(Locale.ROOT) + " did not learn " + this.attackLearning.toUpperCase(Locale.ROOT) + ".", (String) null, (Action) null, this.nextAction))), new DisplayText.Clear(game, new WaitFrames(game, 3, new DisplayText(game, "Which move should be forgotten?", (String) null, true, true, (Action) this))))))));
                    return;
                }
                game.actionStack.remove(this);
                game.insertAction(this.nextAction);
            } else if (InputProcessor.startJustPressed && this.attackLearning == null) {
                this.isSorting = true;
                this.sortingIndex = curr;
            }
            this.textBox.draw(game.uiBatch);
            int j = 0;
            Iterator<ArrayList<Sprite>> it = this.spritesToDraw.iterator();
            while (it.hasNext()) {
                Iterator<Sprite> it2 = it.next().iterator();
                while (it2.hasNext()) {
                    Sprite sprite = it2.next();
                    game.uiBatch.draw(sprite, sprite.getX() + 40.0f, (sprite.getY() - ((float) (j * 8))) + 8.0f);
                }
                j++;
            }
            Attack attack = game.battle.attacks.get(this.pokemon.attacks[curr]);
            String type = attack.type.toUpperCase(Locale.ROOT);
            int qmarkOffset = 0;
            if (type.equals("CURSE_T")) {
                type = "???";
                qmarkOffset = 1;
            }
            char[] textArray = type.toCharArray();
            for (int m = 0; m < textArray.length; m++) {
                game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray[m])), this.offset.x + 16.0f + ((float) (8 * m)), this.offset.y + 56.0f + ((float) qmarkOffset));
            }
            if (Game.specialPhysicalSplitEnabled) {
                char[] textArray2 = attack.category.name().toUpperCase(Locale.ROOT).toCharArray();
                for (int m2 = 0; m2 < textArray2.length; m2++) {
                    game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray2[m2])), this.offset.x + 16.0f + ((float) (8 * m2)), (this.offset.y + 56.0f) - 8.0f);
                }
            }
            if (this.cursorDelay >= 2) {
                this.arrow.setPosition(this.newPos.x + this.offset.x, this.newPos.y + this.offset.y);
                this.arrow.draw(game.uiBatch);
            } else {
                this.cursorDelay++;
            }
            if (this.isSorting && (arrowPos = this.coords.get(Integer.valueOf(this.sortingIndex))) != null) {
                game.uiBatch.draw(this.arrowWhite, arrowPos.x + this.offset.x, arrowPos.y + this.offset.y);
            }
        } else if (this.isSorting) {
            String temp = this.pokemon.attacks[this.sortingIndex];
            this.pokemon.attacks[this.sortingIndex] = this.pokemon.attacks[curr];
            this.pokemon.attacks[curr] = temp;
            this.isSorting = false;
            this.sortingIndex = -1;
            firstStep(game);
        } else if (this.attackLearning != null) {
            game.actionStack.remove(this);
            game.insertAction(new DisplayText.Clear(game, new WaitFrames(game, 3, new DisplayText(game, "Replace " + this.pokemon.attacks[curr].toUpperCase(Locale.ROOT) + "?", (String) null, true, true, (Action) new DrawYesNoMenu(null, new DisplayText.Clear(game, new WaitFrames(game, 3, new DisplayText(game, "And one... two... three... POOF!", (String) null, (Action) null, new DisplayText(game, this.pokemon.nickname.toUpperCase(Locale.ROOT) + " forgot " + this.pokemon.attacks[curr].toUpperCase(Locale.ROOT) + " and...", (String) null, (Action) null, new DisplayText(game, this.pokemon.nickname.toUpperCase(Locale.ROOT) + " learned " + this.attackLearning.toUpperCase(Locale.ROOT) + "!", "fanfare1.ogg", false, true, (Action) new SetArrayAtIndex(this.pokemon.attacks, curr, this.attackLearning, this.nextAction)))))), new DisplayText.Clear(game, new WaitFrames(game, 3, new DisplayText(game, "Which move should be forgotten?", (String) null, true, true, (Action) this))))))));
        } else if (this.pokemon.disabledIndex == curr) {
            game.actionStack.remove(this);
            game.insertAction(new DisplayText.Clear(game, new WaitFrames(game, 3, new DisplayText(game, this.pokemon.attacks[curr].toUpperCase(Locale.ROOT) + " is disabled!", (String) null, (Action) null, new WaitFrames(game, 3, this)))));
        } else {
            game.player.numFlees = 0;
            Action attack2 = new SplitAction(new PlayMusic("click1", (Action) null), null);
            if (game.type == Game.Type.CLIENT) {
                String attackName = this.pokemon.attacks[curr];
                attack2.append(new Battle.WaitTurnData(game, null));
                game.client.sendTCP(new Network.DoBattleAction(game.player.network.id, Battle.DoTurn.Type.ATTACK, attackName));
            }
            attack2.append(new Battle.DoTurn(game, Battle.DoTurn.Type.ATTACK, this.nextAction));
            game.actionStack.remove(this);
            game.insertAction(attack2);
        }
    }
}
